package com.example.zy.car.base;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.zy.car.R;


public abstract class BaseActivityWithTitleBar extends BaseActivity {

    public TextView mTextView_title_left;
    public TextView mTextView_title_right;
    public TextView mTextView_title_center;
    public Activity mActivity;

    @Override
    public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) {
        super.onCreate(savedInstanceState, persistentState);
        mActivity=this;
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    }
    public void MyTransalteActivity(Class activityClass){
        startActivity(new Intent(this,activityClass));
        this.overridePendingTransition(R.anim.enter_in,R.anim.enter_out);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        this.overridePendingTransition(R.anim.extre_in,R.anim.extre_out);
    }

    @Override
    public void setContentView(int layoutResID) {
        LayoutInflater inflater=LayoutInflater.from(this);
        RelativeLayout relativeLayout = new RelativeLayout(this);
        relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

        View titleView = inflater.inflate(R.layout.activity_base_title_bar, relativeLayout, false);
        mTextView_title_center = (TextView) titleView.findViewById(R.id.tv_title_bar_center);
        mTextView_title_right = (TextView) titleView.findViewById(R.id.tv_title_bar_right);
        mTextView_title_left = (TextView) titleView.findViewById(R.id.tv_title_bar_left);
        View contentView=inflater.inflate(layoutResID,relativeLayout,false);

        relativeLayout.addView(titleView);
        relativeLayout.addView(contentView);
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) contentView.getLayoutParams();
        layoutParams.addRule(RelativeLayout.BELOW, R.id.layout_title_bar);
        //在此处我们就把焦点放在标题栏上
        titleView.requestFocus();

        super.setContentView(relativeLayout);
    }

    public void setLeftTitleTv(int strID, View.OnClickListener onClickListener) {
        String text = this.getResources().getString(strID);
        setLeftTitleTv(text, onClickListener);
    }

    public void setRightTitleTv(int strID, View.OnClickListener onClickListener) {
        String text = this.getResources().getString(strID);
        setRightTitleTv(text, onClickListener);
    }

    public void setCenterTitleTv(int strID) {
        String text = this.getResources().getString(strID);
        setCenterTitleTv(text);
    }

    public void setLeftTitleTv(String text, View.OnClickListener onClickListener) {
        mTextView_title_left.setVisibility(View.VISIBLE);
        mTextView_title_left.setText(text);
        mTextView_title_left.setOnClickListener(onClickListener);
    }

    public void setRightTitleTv(String text, View.OnClickListener onClickListener) {
        mTextView_title_right.setVisibility(View.VISIBLE);
        mTextView_title_right.setText(text);
        mTextView_title_right.setOnClickListener(onClickListener);
    }

    public void setCenterTitleTv(String text) {
        mTextView_title_center.setText(text);
    }
//    long frist;
//    public boolean checkCanOut() {
//        if ((System.currentTimeMillis() - frist) > 3000) {
//            Toast.makeText(BaseActivityWithTitleBar.this, "再点击一次退出！", Toast.LENGTH_SHORT).show();
//            frist = System.currentTimeMillis();
//            return false;
//        }
//        return true;
//    }
//    public boolean onBackPressed(){
//        return false;
//    }

}
